package me.fangx.zhihu.adapter;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import me.fangx.zhihu.R;
import me.fangx.zhihu.ui.fragment.CookCategoryFragment;

/**
 * Created by fangxiao on 16/1/25.
 */
public class CookPagerAdapter extends FragmentStatePagerAdapter {

    private Context mContext;

    public static final int PAGE_COUNT = 4;

    public String[] EX_TITLES = null;

    public static final String TYPE = "type";

    public CookPagerAdapter(FragmentManager fm, Context context) {
        super(fm);
        this.mContext = context;
        EX_TITLES = new String[]{mContext.getString(R.string.type_chinese), mContext.getString(R.string.type_thai), mContext.getString(R.string.type_korea), mContext.getString(R.string.type_japanese)};
    }

    @Override
    public Fragment getItem(int i) {
        Bundle bundle = new Bundle();
        CookCategoryFragment newFragment = new CookCategoryFragment();
        bundle.putInt(TYPE, i);
        newFragment.setArguments(bundle);
        return newFragment;
    }

    @Override
    public int getCount() {
        return PAGE_COUNT;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return EX_TITLES[position];
    }


    public CookCategoryFragment getFB(int position) {
        if (getItem(position) != null) {
            return (CookCategoryFragment) getItem(position);
        } else {
            return null;
        }
    }

}
